package com.arsn.myf.common.excel;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import java.util.ArrayList;
import java.util.List;

/**
 * 导入监听器
 * @param <T>
 * @author zhongrj
 */
public class ImportListener<T> extends AnalysisEventListener<T> {

    private List<T> list = new ArrayList();

    private final ExcelImporter<T> importer;

    @Override
    public void invoke(T data, AnalysisContext analysisContext) {
        this.list.add(data);
        // 数据保存操作
        this.importer.save(this.list);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        this.list.clear();
    }

    public List<T> getList() {
        return this.list;
    }

    public ExcelImporter<T> getImporter() {
        return this.importer;
    }

    public void setList(final List<T> list) {
        this.list = list;
    }

    public ImportListener(final ExcelImporter<T> importer) {
        this.importer = importer;
    }
}

